﻿Imports System.IO
Imports System.Runtime.Serialization.Formatters.Binary

Public Class CVSS
    Public lstVss As New List(Of VSS)

    Public Function AddVss(ByVal username As String, _
                           ByVal password As String, _
                           ByVal vssdir As String, _
                           ByVal ShortName As String, _
                           ByVal LastDir As String) As Integer
        Dim cl As New VSS
        cl.VSSDIR = vssdir
        cl.USERNAME = username
        cl.PASSWORD = password
        cl.VSSSETUPPATH = ShortName
        cl.LastDir = LastDir
        lstVss.Add(cl)

        Return True

    End Function

    Public Function SerializableToFile(ByVal strPath As String) As Boolean

        Try
            If System.IO.File.Exists(strPath) Then
                System.IO.File.Delete(strPath)
            End If

            Dim fs As FileStream = New FileStream(strPath, FileMode.Create)
            Dim bf As New BinaryFormatter
            bf.AssemblyFormat = Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
            bf.Serialize(fs, lstVss)
            fs.Close()
            fs.Dispose()
        Catch ex As Exception
            Return False
        End Try

        Return True

    End Function

    Public Function FileToDeSerializable(ByVal strPath As String) As Boolean

        Try
            If Not System.IO.File.Exists(strPath) Then
                Return False
            End If

            Dim fs As New FileStream(strPath, FileMode.Open, FileAccess.Read)
            Dim bf As New BinaryFormatter
            bf.AssemblyFormat = Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
            lstVss = bf.Deserialize(fs)
            fs.Close()
            fs.Dispose()
        Catch ex As Exception
            Return False
        End Try

        Return True

    End Function

End Class

Public Class CFormSetting

    Public fs1 As New FormSetting
    Public Function SerializableToFile(ByVal strPath As String) As Boolean

        Try
            If System.IO.File.Exists(strPath) Then
                System.IO.File.Delete(strPath)
            End If

            Dim fs As FileStream = New FileStream(strPath, FileMode.Create)
            Dim bf As New BinaryFormatter
            bf.AssemblyFormat = Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
            bf.Serialize(fs, fs1)
            fs.Close()
            fs.Dispose()
        Catch ex As Exception
            Return False
        End Try

        Return True

    End Function

    Public Function FileToDeSerializable(ByVal strPath As String) As Boolean
        Try
            If Not System.IO.File.Exists(strPath) Then
                Return False
            End If

            Dim fs As New FileStream(strPath, FileMode.Open)
            Dim bf As New BinaryFormatter
            bf.AssemblyFormat = Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
            fs1 = bf.Deserialize(fs)
            fs.Close()
            fs.Dispose()
        Catch ex As Exception
            fs1 = New FormSetting
        End Try

        Return True

    End Function

End Class

<Serializable()> _
Public Class VSS
    Public USERNAME As String = ""
    Public PASSWORD As String = ""
    Public VSSDIR As String = ""
    Public VSSSETUPPATH As String = ""
    Public LastDir As String = ""
    Public EncodePage As Integer = System.Text.Encoding.Default.WindowsCodePage
End Class

<Serializable()> _
Public Class FormSetting
    Public width As Integer = 562
    Public height As Integer = 327
End Class